<template>
	<view class="main">
		<uv-form labelPosition="left" :model="form" :rules="rules" labelWidth="120rpx" ref="form">

			<uv-form-item label="账号" required prop="username" borderBottom>
				<uv-input v-model="form.username" border="none" placeholder="请输入账号"></uv-input>
			</uv-form-item>

			<uv-form-item label="密码" required prop="password" borderBottom>
				<uv-input type='password' v-model="form.password" border="none" placeholder="请输入密码"></uv-input>
			</uv-form-item>

		</uv-form>

		<view class="btn">
			<uv-button type="primary" shape="circle" @click="submit" text="绑定" color="#006633"></uv-button>
		</view>
	</view>
</template>

<script>
	import {
		bingUser
	} from '@/api/common.js'
	export default {
		data() {
			return {
				form: {
					userId: '',
					username: '',
					password: '',
				},
				rules: {
					'username': {
						type: 'string',
						required: true,
						message: '请输入账号',
						trigger: ['blur', 'change']
					},
					'password': {
						type: 'string',
						required: true,
						message: '请输入密码',
						trigger: ['blur', 'change']
					},
				}
			}
		},
		onLoad(o) {
			this.form.userId = o.userId
		},
		methods: {
			submit() {
				this.$refs.form.validate().then(res => {
					bingUser(this.form).then(res => {
						uni.showToast({
							icon: 'none',
							title: res.data.message
						})
						if (res.data.code == 200) {
							uni.setStorageSync('userInfo', res.data.result)
							if(res.data.result.role == 3 ){
								uni.requestSubscribeMessage({
								  tmplIds: ['mT19oJTmbNNpuNTzyhxpUKZmrv5ydCvQnzNJktfmBxY'],
								  success (res) { }
								})
							}
							uni.navigateBack()
						}
					})
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.main {
		height: 100vh;
		position: relative;

		/deep/.uv-form {
			padding: 0 40rpx;

			.uv-form-item__body__left__content__required {
				left: -13px;
			}
		}

		.btn {
			position: fixed;
			bottom: 20rpx;
			width: 90%;
			left: 5%;
			z-index: 99;
		}
	}
</style>